package com.zzyl.nursing.service.impl;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzyl.nursing.domain.MemberReservation;
import com.zzyl.nursing.mapper.MemberReservationMapper;
import com.zzyl.nursing.service.IMemberReservationService;
import org.apache.poi.ss.formula.functions.Intercept;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Service
public class MemberReservationImpl extends ServiceImpl<MemberReservationMapper, MemberReservation> implements IMemberReservationService {
    @Autowired
    private MemberReservationMapper memberReservationMapper;
    /**
     * 根据用户id查询取消预约数量
     * */
    @Override
    public Integer getCancelledReservationCount(Long userId) {
        long time = System.currentTimeMillis();
        LocalDateTime ldt = LocalDateTimeUtil.of(time);
        LocalDateTime startTime = ldt.toLocalDate().atStartOfDay();
        LocalDateTime endTime = startTime.plusDays(1);
        return memberReservationMapper.selectCancelCountsById(startTime, endTime, userId);
    }

    /**
     * 查询每个时间段剩余预约次数
     * */
    @Override
    public List<Map<String, Object>> countByTime(Long time) {
        long tempTime = System.currentTimeMillis();
        LocalDateTime ldt = LocalDateTimeUtil.of(tempTime);
        LocalDateTime startTime = ldt.toLocalDate().atStartOfDay();
        LocalDateTime endTime = DateTime.of(time).toLocalDateTime();
        List<Map<String, Object>> list = memberReservationMapper.countByTime(startTime, endTime);
        return List.of();
    }
}
